package com.aacar.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
import java.util.Random;


/**
 * 生成token
 * @author 王辉
 *
 */
public class TokenUtil {
	

	public static String generatorToken() {
		String token = System.currentTimeMillis()+new Random().nextInt()+"";
		MessageDigest md;
		String encodedText = null;
		Base64.Encoder encoder = null;
		try {
			md = MessageDigest.getInstance("md5");
			byte[] md5 = md.digest(token.getBytes());
			encoder = Base64.getEncoder();
			encodedText = encoder.encodeToString(md5);
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		
		return encodedText;
	}
	
	public static String generateSmsCode() {
		int code = (int)((Math.random()*9+1)*100000);
		return String.valueOf(code);
	}
	
	public static void main(String[] args) {
		System.out.println(generateSmsCode());
	}
}
